package com.why.service.impl;

import com.why.dao.UserAddressMapper;
import com.why.pojo.UserAddress;
import com.why.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public UserAddress selectByPrimaryKey(Integer id) {
        return userAddressMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<UserAddress> selectAddressByUserId(Integer userid) {
        return userAddressMapper.selectAddressByUserId(userid);
    }

    @Override
    public boolean insertSelective(UserAddress record) {
        record.setIsdefault(0);
        record.setCreatetime(new Date());
        if (userAddressMapper.insertSelective(record)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteByPrimaryKey(Integer id) {
        if (userAddressMapper.deleteByPrimaryKey(id)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateByPrimaryKeySelective(UserAddress record) {
        if (userAddressMapper.updateByPrimaryKeySelective(record)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAllIsDefault(UserAddress userAddress) {
        if (userAddressMapper.updateAllIsDefault(userAddress.getUserid())>=1){
            if (userAddressMapper.updateIsDefault(userAddress)==1){
                return true;
            }
        }
        return false;
    }
}
